#include <54func.h>
int main(int argc,char *argv[])
{
    // ./3_A 1.pipe
    ARGS_CHECK(argc,2);
    int fdr_pipe = open(argv[1],O_RDONLY);
    ERROR_CHECK(fdr_pipe,-1,"open read");

    //读文件名
    char filename[4096] = {0}; 
    read(fdr_pipe,filename,sizeof(filename));//把文件名读取到filename上
    //在当前文件夹下创建一个dir目录，在该目录下创建该文件
    char path[8192] = {0};//文件路径
    char dir[] = "dir2/";
    mkdir(dir,0777);//创建该目录
    sprintf(path,"%s%s%s",dir,"/",filename);
    //创建文件
    int fdw_file = open(path,O_WRONLY|O_CREAT|O_TRUNC,0666);
    ERROR_CHECK(fdw_file,-1,"open write");


    //读文件内容
    char buf[4096] = {0};
    ssize_t sret = read(fdr_pipe,buf,sizeof(buf));
    write(fdw_file,buf,sret);

    close(fdr_pipe);
    close(fdw_file);
    return 0;
}
